package com.c6906.vdam.das.schedule;

import cn.hutool.core.date.DateUtil;
import com.c6906.vdam.das.config.DasOpenStatus;
import com.c6906.vdam.das.service.AlarmService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@EnableConfigurationProperties({DasOpenStatus.class})
public class IlleagalParkAnalysis {

    public static final Logger logger = LoggerFactory.getLogger(IlleagalParkAnalysis.class);

    @Resource
    DasOpenStatus openStatus;
    @Resource
    AlarmService alarmService;

    /**
     * 7:30违规停车定时任务
     */
    @Scheduled(cron = "0 30 7 * * *")
    public void analysisParkingAlarm() {
        if (openStatus.isOpenStatus() && openStatus.isOpenLastGpsToRedis()) {
            // 车辆在晚上8点到早7点的停放数据
            logger.info("【违规停车】开始执行定时任务......");
            String date = DateUtil.yesterday().toDateStr();
            alarmService.analyzeIllegalParking(date);
            logger.info("【违规停车】结束执行定时任务......");
        }
    }
}
